package com.whl.mybatis.helper;

import java.util.LinkedList;
import java.util.List;

public class OrderBy {

	private String property;
	private OrderByType orderByType;

	public String getProperty() {
		return property;
	}

	public void setProperty(String property) {
		this.property = property;
	}

	public OrderByType getOrderByType() {
		return orderByType;
	}

	public void setOrderByType(OrderByType orderByType) {
		this.orderByType = orderByType;
	}

	public static class Builder {
		private List<OrderBy> orderBys = new LinkedList<>();

		public Builder add(String property) {
			this.add(property, null);
			return this;
		}

		public Builder add(String property, OrderByType orderByType) {
			OrderBy orderBy = new OrderBy();
			orderBy.setProperty(property);
			if (orderByType == null) {
				orderBy.setOrderByType(OrderByType.ASC);
			}else{
				orderBy.setOrderByType(orderByType);
			}
			orderBys.add(orderBy);
			return this;
		}

		public List<OrderBy> build() {
			return this.orderBys;
		}

	}

	public static void main(String[] args) {
		List<OrderBy> dds = new OrderBy.Builder().add("name", OrderByType.DESC).add("id").build();
		for (OrderBy orderBy : dds) {
			System.out.println(orderBy.getProperty()+"  " + orderBy.getOrderByType().toString());
		}
	}
}
